﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;

namespace XNA_Game_Engine.Sounds
{
    public static class SoundController
    {
        public static Song fase1;
        public static Song menuMusic;
        public static Song lvlCompleted; 
        static String previousSong;
        public static SoundEffect slot;
        public static SoundEffect slotMiss;
        public static SoundEffect robotDeath;
        public static SoundEffect moveAhead;
        public static SoundEffect turn;
        public static SoundEffect jump;
        public static SoundEffect enemyKill;


        public static void playSound(String name)
        {
            
            if (MediaPlayer.GameHasControl && !MediaPlayer.IsMuted)
            {
                //MediaPlayer.Stop();

                try
                {
                    if (name != previousSong)
                    {
                      switch (name)
                        {

                            case "menu":
                                {
                                    MediaPlayer.Play(menuMusic);
                                    MediaPlayer.Volume = 0.6f;
                                    MediaPlayer.IsRepeating = true;
                                }
                                break;

                            case "fase1":
                                {
                                    MediaPlayer.Play(fase1);
                                    MediaPlayer.Volume = 0.3f;
                                    MediaPlayer.IsRepeating = true;
                                }
                                break;

                            case "levelCompleted":
                                {                                    
                                    MediaPlayer.Play(lvlCompleted);
                                    MediaPlayer.Volume = 0.6f;
                                    MediaPlayer.IsRepeating = false;
                                }
                                break;
                                
                        }
                    }
                    previousSong = name;
                }
                catch (InvalidOperationException) { }
            }
        }

        public static void playClip(String nome)
        {
            if (!MediaPlayer.IsMuted)

                switch (nome)
                {
                    case "slot":
                        {
                            slot.Play(0.7f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }

                    case "slotMiss":
                        {
                            slotMiss.Play(0.7f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }

                    case "death":
                        {
                            robotDeath.Play(0.7f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }
                    case "move":
                        {
                            moveAhead.Play(0.8f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }
                    case "turn":
                        {
                            turn.Play(0.8f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }
                    case "jump":
                        {
                            jump.Play(0.8f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }
                    case "enemyKill":
                        {
                            enemyKill.Play(0.8f, 0.0f, 0.0f); //Volume , Pan, Pitch
                            break;
                        }
                }
        }



        public static void mute()
        {                     
            MediaPlayer.IsMuted = true;
        }

        public static void unMute()
        {
            MediaPlayer.IsMuted = false;
        }

        public static Boolean isSoundMuted()
        {
            return MediaPlayer.IsMuted;
        }

    }
}
